package com.jiguang.shangcheng.servlet;

import cn.hutool.core.text.escape.Html4Escape;
import com.jiguang.shangcheng.dao.AdminDao;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/admin/admin_deleteOrder")
public class adminDeleteOrder extends HttpServlet {
    @SneakyThrows
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置字符集
        resp.setContentType("text/html;charset=utf-8");
        req.setCharacterEncoding("UTF-8");



        //获取参数
        String id = req.getParameter("id");
        String cp = req.getParameter("cp");

        //删除该订单
        boolean result = AdminDao.deleteOrder(Integer.parseInt(id));
        if(result){
            resp.sendRedirect("admin_order?cp="+cp);
        }else{
            PrintWriter out = resp.getWriter();
            out.println("<script>alert('删除失败');location.href='/admin/admin_product"+cp+"';</script>");
        }
    }
}
